import logging

import requests

class Test():
    uid = ""
    sid = ""
    def setup_method(self):
        print("执行前用例")

    def teardown_method(self):
        print("执行后用例")
    #Cese1:登录接口参数--正例
    def test_denglu(self):
        try:
            url="http://10.59.9.18/small/user/v1/login"
            doby={"phone":"13811033965","pwd":"123456Aa"}
            hds={"Content-Type":"application/json"}
            r = requests.post(url=url,json=doby,headers=hds)
            Test.uid = r.json()['result']['userId']
            Test.sid = r.json()['result']['sessionId']
            print("登录",r.json())
        except Exception as e:
            logging.info(e)
            assert r.status_code == 200
            assert "登录成功" == r.text
    #Cese2:商品详情列表接口参数--正例
    def test_shangpin(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/commodityList"
            hds = {"userId":str(Test.uid),"sessionId":str(Test.sid)}
            r = requests.get(url=url,headers=hds)
            print("商品详情列表",r.json())
        except Exception as e:
            logging.info(e)
            assert r.status_code == 200
            assert "小白鞋 女款 时尚百搭休闲板鞋" == r.text
    #Cese3:商品详情页面接口参数--正例
    def test_shangpi(self):
        try:
            url="http://10.59.9.18/small/commodity/v1/findCommodityDetailsById?commodityId=6"
            hds = {"userId":str(Test.uid),"sessionId":str(Test.sid)}
            r = requests.get(url=url,headers=hds)
            print("商品详情列表",r.json())
        except Exception as e:
            logging.info(e)
            assert r.status_code == 200
            assert "美妆护肤" == r.text

    #Cese4: 查询商品信息接口参数 - -正例
    def test_shangp(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/findShoppingCart"
            hds = {"userId":str(Test.uid),"sessionId":str(Test.sid)}
            r = requests.get(url=url,headers=hds)
            print("商品详情列表",r.json())
        except Exception as e:
            logging.info(e)
            assert r.status_code == 200
            assert "美妆护肤" == r.text

    #Cese5: 根据订单状态查询订单信息 - -正例
    def test_shang(self):
        try:
            url="http://10.59.9.18/small/order/verify/v1/findOrderListByStatus?status=1&page=1&count=5"
            hds = {"userId":str(Test.uid),"sessionId":str(Test.sid)}
            r = requests.get(url=url,headers=hds)
            print("商品详情列表",r.json())
        except Exception as e:
            logging.info(e)
            assert r.status_code == 200
            assert "秋冬季真皮兔毛女鞋韩版休闲平底毛毛鞋软底百搭浅口水钻加绒棉鞋毛毛鞋潮鞋" == r.text
